package rad.framework.mda.generator.template.test.java.service;

import java.util.*;
import rad.framework.mda.generator.util.*;
import org.eclipse.emf.codegen.util.*;

public class ComponentJUnit
{
  protected static String nl;
  public static synchronized ComponentJUnit create(String lineSeparator)
  {
    nl = lineSeparator;
    ComponentJUnit result = new ComponentJUnit();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package ";
  protected final String TEXT_2 = ";";
  protected final String TEXT_3 = NL;
  protected final String TEXT_4 = NL + NL + "/**" + NL + " * Unit tests for the ";
  protected final String TEXT_5 = "." + NL + " *" + NL + " * @author ";
  protected final String TEXT_6 = NL + " * @generated" + NL + " */" + NL + "public class ";
  protected final String TEXT_7 = "Test extends ContainerTestCase {" + NL + "" + NL + "\t/** @generated */" + NL + "\tprivate static final Log log = LogFactory.getLog(";
  protected final String TEXT_8 = "Test.class);" + NL + "" + NL + "\t/**" + NL + "\t * The service under test." + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
  protected final String TEXT_9 = " service;" + NL + "" + NL + "\t/**" + NL + "\t * The service parameter." + NL + "\t * @generated" + NL + "\t */";
  protected final String TEXT_10 = NL + "\tprivate static ";
  protected final String TEXT_11 = " entity;" + NL + "" + NL + "\t/** @generated */" + NL + "\tpublic ";
  protected final String TEXT_12 = "Test(String arg0) {" + NL + "\t\tsuper(arg0);" + NL + "\t}" + NL + "" + NL + "\t/** @generated */" + NL + "\tprotected void setUp() throws Exception {" + NL + "\t\tsuper.setUp();" + NL + "\t\t// EventUtil.setDisableForUnitTesting(true);" + NL + "\t}" + NL + "" + NL + "\t/** @generated */" + NL + "\tprotected void tearDown() throws Exception {" + NL + "\t\tsuper.tearDown();" + NL + "\t\t// EventUtil.setDisableForUnitTesting(false);" + NL + "\t}" + NL + "" + NL + "\t/** @generated */" + NL + "\tpublic static Test suite() {" + NL + "\t\tTestSuite suite = new TestSuite();" + NL + "\t\tsuite.addTest(new ";
  protected final String TEXT_13 = "Test(\"testInitDB\"));";
  protected final String TEXT_14 = NL + "\t\tsuite.addTest(new ";
  protected final String TEXT_15 = "Test(\"test";
  protected final String TEXT_16 = "\"));";
  protected final String TEXT_17 = NL + "\t\treturn new Bootstrap(suite);" + NL + "\t}" + NL + "    " + NL + "\t/** @generated */" + NL + "\tpublic void testInitDB() throws Exception {" + NL + "\t\tnew TransactionScript(\"java:/";
  protected final String TEXT_18 = "\") {" + NL + "" + NL + "\t\t\t@Override" + NL + "\t\t\tprotected Object run(EntityManager em) {" + NL + "\t\t\t\treturn null;" + NL + "\t\t\t}" + NL + "\t\t}.run();" + NL + "\t}" + NL + "    " + NL + "\t/**" + NL + "\t * Populate the parameter object with test values." + NL + "\t */" + NL + "\tprivate void create() {" + NL + "\t\tentity = new ";
  protected final String TEXT_19 = "();" + NL + "\t\t// TODO implement this method" + NL + "\t}    ";
  protected final String TEXT_20 = NL + NL + "\t/**" + NL + "\t * Test the ";
  protected final String TEXT_21 = " operation." + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void test";
  protected final String TEXT_22 = "() throws Exception {" + NL + "\t\tnew ComponentTest() {" + NL + "\t\t\tprotected void testComponents() throws Exception {" + NL + "\t\t\t\tservice = ";
  protected final String TEXT_23 = "Bean.instance();" + NL + "\t";
  protected final String TEXT_24 = NL + "\t\t\t\tLong id = entity.getId();" + NL + "\t\t\t\tservice.";
  protected final String TEXT_25 = "(entity);" + NL + "\t\t\t\tassertNull(service.get(id));" + NL + "\t\t\t\tlog.debug(\"deleted:\" + id);";
  protected final String TEXT_26 = NL + "\t\t\t\tcreate();" + NL + "\t\t\t\tentity = service.";
  protected final String TEXT_27 = "(entity);" + NL + "\t\t\t\tassertNotNull(entity);" + NL + "\t\t\t\tlog.debug(\"saved:\" + entity);";
  protected final String TEXT_28 = NL + "\t\t\t\tObject o = service.get(entity.getId());" + NL + "\t\t\t\tassertNotNull(o);" + NL + "\t\t\t\tlog.debug(\"exists:\" + o);";
  protected final String TEXT_29 = NL + "\t\t\t\t";
  protected final String TEXT_30 = " example = new ";
  protected final String TEXT_31 = "();" + NL + "\t\t\t\tList<";
  protected final String TEXT_32 = "> list = service.query(example, new Long(0), new Long(10), \"id\");" + NL + "\t\t\t\tassertNotNull(list);" + NL + "\t\t\t\tassertTrue(list.size() > 0);" + NL + "\t\t\t\tIterator<";
  protected final String TEXT_33 = "> i = list.iterator();" + NL + "\t\t\t\twhile (i.hasNext()) {" + NL + "\t\t\t\t\tlog.debug(\"returned: \" + i.next());" + NL + "\t\t\t\t}";
  protected final String TEXT_34 = NL + "\t\t\t\t// TODO implement this test" + NL + "\t\t\t\tentity = service.";
  protected final String TEXT_35 = "(entity);";
  protected final String TEXT_36 = NL + "\t\t\t}" + NL + "\t\t}.run();" + NL + "\t}";
  protected final String TEXT_37 = NL + "}";
  protected final String TEXT_38 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    org.eclipse.uml2.uml.Interface uml2Interface = (org.eclipse.uml2.uml.Interface) argument;org.eclipse.uml2.uml.Package uml2Package = uml2Interface.getPackage();
    ImportManager importManager=null;
    if (NameHelper.getQualifiedName(uml2Package) != null) {
    importManager = ImportHelper.makeImportManager(NameHelper.getQualifiedName(uml2Package));
    stringBuffer.append(TEXT_1);
    stringBuffer.append(NameHelper.getQualifiedName(uml2Package));
    stringBuffer.append(TEXT_2);
    } else {
    importManager = ImportHelper.makeImportManager("");
    }
    stringBuffer.append(TEXT_3);
    importManager.addImport("java.util.Iterator");
    importManager.addImport("java.util.List");
    importManager.addImport("junit.framework.Test");
    importManager.addImport("junit.framework.TestSuite");
    importManager.addImport("rad.framework.embedded.Bootstrap");
    importManager.addImport("rad.framework.embedded.ContainerTestCase");
    importManager.addImport("org.apache.commons.logging.Log");
    importManager.addImport("org.apache.commons.logging.LogFactory");
    importManager.addImport("javax.persistence.EntityManager");
    importManager.addImport("rad.framework.jpa.TransactionScript");
    
StringBuffer importStringBuffer = stringBuffer;
int importInsertionPoint = stringBuffer.length();
importManager.addCompilationUnitImports(stringBuffer.toString());

    stringBuffer.append(TEXT_4);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_5);
    stringBuffer.append(System.getProperty("user.name"));
    stringBuffer.append(TEXT_6);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_7);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_8);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_9);
    String type = null;
    for (Iterator i=uml2Interface.getOwnedOperations().iterator(); i.hasNext();) { org.eclipse.uml2.uml.Operation operation = (org.eclipse.uml2.uml.Operation)i.next();
    type = InterfaceHelper.getFirstParameterType(operation);
    }//for
    stringBuffer.append(TEXT_10);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_11);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_12);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_13);
    for (Iterator i=uml2Interface.getOwnedOperations().iterator(); i.hasNext();) { org.eclipse.uml2.uml.Operation operation = (org.eclipse.uml2.uml.Operation)i.next();
    stringBuffer.append(TEXT_14);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_15);
    stringBuffer.append(NameHelper.getCapName(operation));
    stringBuffer.append(TEXT_16);
    }//for
    stringBuffer.append(TEXT_17);
    stringBuffer.append(uml2Interface.getModel().getName());
    stringBuffer.append(TEXT_18);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_19);
    for (Iterator i=uml2Interface.getOwnedOperations().iterator(); i.hasNext();) { org.eclipse.uml2.uml.Operation operation = (org.eclipse.uml2.uml.Operation)i.next();
    stringBuffer.append(TEXT_20);
    stringBuffer.append(NameHelper.getCapName(operation));
    stringBuffer.append(TEXT_21);
    stringBuffer.append(NameHelper.getCapName(operation));
    stringBuffer.append(TEXT_22);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_23);
    if ("delete".equals(operation.getName())) {
    stringBuffer.append(TEXT_24);
    stringBuffer.append(operation.getName());
    stringBuffer.append(TEXT_25);
    }else { if ("save".equals(operation.getName())) {
    stringBuffer.append(TEXT_26);
    stringBuffer.append(operation.getName());
    stringBuffer.append(TEXT_27);
    }else { if ("get".equals(operation.getName()) || "find".equals(operation.getName())) {
    stringBuffer.append(TEXT_28);
    }else { if ("query".equals(operation.getName())) {
    stringBuffer.append(TEXT_29);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_30);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_31);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_32);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_33);
    }else {
    stringBuffer.append(TEXT_34);
    stringBuffer.append(operation.getName());
    stringBuffer.append(TEXT_35);
    }}}}
    stringBuffer.append(TEXT_36);
    }//for
    stringBuffer.append(TEXT_37);
    importStringBuffer.insert(importInsertionPoint, importManager.computeSortedImports());
    stringBuffer.append(TEXT_38);
    return stringBuffer.toString();
  }
}
